<?php 
$sort1=isset($_GET['sort'])?'&sort='.$_GET['sort']:'';
$cs=Yii::app()->clientScript;
$cs->registerScript('appointment_excel',<<<END
$("#excel").click(
function(){
	var act=$("form").attr('action');
	$("form").attr('action',act+'&excel=1$sort1').attr('target','_blank').submit().attr('action',act).attr('target','');
}
);
END
);
$create_confirm_id=Yii::app()->params['create_confirm_id'];
$cs->registerScript('appointment_to_confirm',<<<END
$(".to_confirm").click(
function(){
	var exists=true;
	var tab=parent.tab;
	var n = tab.getComponent('$create_confirm_id');
	if(n){
		exists=confirm('确认派车单窗口已存在，是否关闭已有窗口进行 确认?');
		if(exists) tab.remove('$create_confirm_id');
	}
	if(exists){
		n = tab.add({'id':'$create_confirm_id','title':'确认派车单',	closable:true,height:'100px',
            html: "<iframe class='$create_confirm_id' scrolling='auto' frameborder='0' width='100%' height='100%' src='?r=confirm_sheet/create&aid="+$(this).attr('id')+"'></iframe>"});
        tab.setActiveTab(n);  
	}
}
);
END
);
?>
<?php if($search):?>
<h2>查询派车单</h2>
<?php else:?>
<h2>修改派车单</h2>
<?php endif?>
<?php echo CHtml::beginForm(array($search?'search':'admin'),'post');?>
<table  style="margin: 0 auto;"  width="1240">
<tr><td>
	派车单号：<input type="text" name="keys[truck_appointment.appointment_no]" size="9" value="<?php echo isset($_GET['keys']['truck_appointment.appointment_no'])?$_GET['keys']['truck_appointment.appointment_no']:'';?>"/>
	车牌号：<input type="text" name="keys[trucks.plate_no]" size="7" value="<?php echo isset($_GET['keys']['trucks.plate_no'])?$_GET['keys']['trucks.plate_no']:'';?>"/>
	司机1：<input type="text" name="keys[driver1.name]" size="7" value="<?php echo isset($_GET['keys']['driver1.name'])?$_GET['keys']['driver1.name']:'';?>"/>
	业务时间：<input type="text" id="keys[s_date]" name="keys[s_date]" size="7" value="<?php echo isset($_GET['keys']['s_date'])?$_GET['keys']['s_date']:'';?>"/>
	<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'keys[s_date]','ifFormat'=>'%Y-%m'));?>
	模糊查询：<input type="radio" name="keys[blur]" value="1" checked/>是  
	<input type="radio" name="keys[blur]" value="0" <?php echo isset($_GET['keys']['blur'])&&$_GET['keys']['blur']==0?'checked':'';?>/>否 
	<input type="submit" value="搜索"/>&nbsp;&nbsp;&nbsp;&nbsp;<input id="excel" type="button" value="输出excel文件"/>
</td></tr></table>
<?php echo CHtml::endForm();?>
<table class="dataGrid" width="1240">
  <thead>
  <tr>
    <th width="90"><?php echo $sort->link('appointment_no'); ?></th>
    <th width="70"><?php echo $sort->link('loading_status'); ?></th>
    <th width="70"><?php echo $sort->link('truck_plate_no'); ?></th>
    <th width="80"><?php echo $sort->link('board_plate_no'); ?></th>
    <th width="70"><?php echo $sort->link('type'); ?></th>
    <th width="80"><?php echo $sort->link('driver1_name'); ?></th>
    <th width="100"><?php echo $sort->link('consignor_name'); ?></th>
    <th width="100"><?php echo $sort->link('consignee_name'); ?></th>
    <th width="80"><?php echo $sort->link('goods_name'); ?></th>
    <th width="80"><?php echo $sort->link('origin'); ?></th>
    <th width="80"><?php echo $sort->link('destination'); ?></th>
    <th width="80"><?php echo $sort->link('goods_demand_deliver_time'); ?></th>
    <th width="80"><?php echo $sort->link('business_time'); ?></th>
	<?php if(!$search):?><th  width="80">操作</th><?php endif ?>
  </tr>
  </thead>
  <tbody>
<?php foreach($models as $n=>$model): ?>
  <tr class="<?php echo $n%2?'even':'odd';?>">
    <?php 
    	$url=array('show','id'=>$model->id)+$_GET;//把所有参数包括页码、查询参数传入显示信息页面
    	$url['ret']=$search?'search':'admin';
    ?>
    <td><?php echo CHtml::link($model->appointment_no,$url); ?></td>
    <td><?php echo CHtml::encode($model->getLoadingStatusName()); ?></td>
    <td><?php echo CHtml::encode($model->truck_plate_no); ?></td>
    <td><?php echo CHtml::encode($model->board_plate_no); ?></td>
    <td><?php echo CHtml::encode($model->type); ?></td>
    <td><?php echo CHtml::encode($model->driver1_name); ?></td>
    <td><?php echo CHtml::encode($model->consignor_name); ?></td>
    <td><?php echo CHtml::encode($model->consignee_name); ?></td>
    <td><?php echo CHtml::encode($model->goods_name); ?></td>
    <td><?php echo CHtml::encode($model->origin); ?></td>
    <td><?php echo CHtml::encode($model->destination); ?></td>
    <td><?php echo CHtml::encode(substr($model->goods_demand_deliver_time,0,10)); ?></td>
    <td><?php echo CHtml::encode($model->business_time); ?></td>
    <?php if(!$search):?>
    <td>
      <?php echo CHtml::link('修改',array('update','id'=>$model->id)+$_GET); ?>
     <?php echo CHtml::link('删除',array('delete','id'=>$model->id)+$_GET,array('confirm'=>"确定要删除派车单号：{$model->appointment_no} 的派车单吗？")); ?>
     <?php echo CHtml::link('确认','#',array('class'=>'to_confirm','id'=>$model->id)); ?>
	</td>
	<?php endif ?>
  </tr>
<?php endforeach; ?>
  </tbody>
</table>
<br/>
<?php $this->widget('CLinkPager',array('pages'=>$pages,'htmlOptions'=>array('style'=>'width:1240px;'))); ?>
